<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>vue-router</title>
  </head>
  <body>
    <pre>
        编程式导航
    </pre>
    <div id="app">
      <!-- 声明式导航 -->
      <router-link to="/model">model</router-link>
      <router-link to="/model2">model2</router-link>
      <router-view></router-view>
    </div>
    <script src="../node_modules/vue/dist/vue.js"></script>
    <script src="../node_modules/vue-router/dist/vue-router.js"></script>
    <script>
      const model = {
        template: `
          <div>这是我的model<button @click='run'>单击</button></div>
          `,
        methods: {
          run() {
            this.$router.go('/model2')
            console.log('run')
          },
        },
      }

      const model2 = {
        template: `
          <div>这是modle2</div>
          `,
      }

      const routers = new VueRouter({
        routes: [
          { path: '/model', component: model },
          { path: '/model2', component: model2 },
        ],
      })

      const vm = new Vue({
        el: '#app',
        data: {},
        router: routers,
      })
    </script>
  </body>
</html>
